//导入 router 模块
import { createRouter, createWebHistory, createWebHashHistory } from "vue-router";

const routes = [
    {
        path: "/",
        redirect: "/Login",
    },
    {
        path: "/Login",
        name: "Login",
        component: () => import("@/views/Login/index.vue"),
    },
    {
        path: "/PermissionRequest",
        name: "PermissionRequest",
        component: () => import("@/views/PermissionRequest/index.vue"),
        meta: {
            title: "应用权限申请",
        },
    },
    {
        path: "/UpdateRequest",
        name: "UpdateRequest",
        component: () => import("@/views/UpdateRequest/index.vue"),
        meta: {
            title: "员工资料更新申请",
        },
    },
];

const router = createRouter({
    history: createWebHashHistory(),
    routes,
});

router.beforeEach((to, from, next) => {
    document.title = to.meta.title || "AMP";
    if (to.path !== "/Login") {
        //存储地址栏#之后地址
        sessionStorage.setItem("amp_redirect", to.fullPath);
    }
    if (to.path === "/Login") {
        next();
    } else {
        if (sessionStorage.getItem("amp_token")) {
            next();
        } else {
            next("/Login");
        }
    }
});

export default router;
